<template>
  <div class="row">
    <div v-if="loading">Loading...</div>
    <div class="card" v-else-if="!!users.length" v-for="user in users" :key="user.id">
      <a :href="user.html_url" target="_blank">
        <img
          :src="user.avatar_url"
          style="width: 100px"
        />
      </a>
      <p class="card-text">{{user.login}}</p>
    </div>
    <h1 v-else>请输入用户名！</h1>
  </div>
</template>

<script>
export default {
  name: "List",
  data() {
    return {
      loading: false,
      users: [],
    };
  },
  mounted() {
    this.$bus.$on("isLoading", this.isLoading);
    this.$bus.$on("setList", this.setList);
  },
  beforeDestroy() {
    this.$bus.$off("isLoading", this.isLoading);
    this.$bus.$off("setList", this.setList);
  },
  methods: {
    isLoading(value) {
      this.loading = value;
    },
    setList(list){
      this.users=list
    }
  },
};
</script>

<style>

</style>